<?php

    include(dirname(dirname(__FILE__)).'/accesobd.php');
    //include('extraerPreguntas.php');
    
    $factura = $_POST["factu"];

    if ($factura){  
        $query = pg_query($conex,"SELECT fact.nfactura FROM factura as fact WHERE fact.nfactura = $factura");

        $nro = pg_fetch_array($query);
        
        if(!$nro[0]){
            echo '<script type="text/javascript">', 'window.alert("Error: Factura no asociada");',
                    'location.reload(true);', 'window.location.assign("../plantilla/index.php");', '</script>';
        }else{
            $sente = pg_query($conex,"SELECT fact.idenc FROM factura as fact WHERE fact.nfactura = $factura");

            $idencuesta = pg_fetch_array($sente);

            $dato = extraer($idencuesta);
            
            echo '<input hidden name="variable" value="'.$idencuesta[0].'"></input>';
            
//            echo '<form class="forms" method="POST" action="http://localhost/trunk/AutoGuayana_BD/plantilla/Guardado/extraerpreguntas.php">', 
           echo '<fieldset>',
                '<ol>',"<hi>".$dato[0]."</hi>",
                    '<li class="form-row text-input-row">
                        <br/>
                        <label><strong>Respuesta 1:</strong></label>
                        <input type="text" name="preg_dpto1" class="text-input required" required/>
                    </li>
                    <li class="form-row text-input-row">
                        <label><strong>Pregunta 2:</strong></label>
                        <input type="text" name="preg_dpto2" class="text-input required" required/>
                    </li>
                    <li class="form-row text-input-row">
                        <label><strong>Pregunta 3:</strong></label>
                        <input type="text" name="preg_dpto3" class="text-input required" required/>
                    </li>
                    <li class="form-row text-input-row">
                        <label><strong>Pregunta 4:</strong></label>
                        <input type="text" name="preg_dpto4" class="text-input required" required/>
                    </li>
                    <h2>Vendedor</h2>
                    <li class="form-row text-input-row">
                        <label><strong>Pregunta 1:</strong></label>
                        <input type="text" name="preg_ven1" class="text-input required" required/>
                    </li>
                    <li class="form-row text-input-row">
                        <label><strong>Pregunta 2:</strong></label>
                        <input type="text" name="preg_ven2" class="text-input required" required/>
                    </li>
                    <li class="form-row text-input-row">
                        <label><strong>Pregunta 3:</strong></label>
                        <input type="text" name="preg_ven3" class="text-input required" required/>
                    </li>
                    <li class="form-row text-input-row">
                        <label><strong>Pregunta 4:</strong></label>
                        <input type="text" name="preg_ven4" class="text-input required" required/>
                    </li>
                    <h2>Vehículo</h2>
                    <li class="form-row text-input-row">
                        <label><strong>Pregunta 1:</strong></label>
                        <input type="text" name="preg_veh1" class="text-input required" required/>
                    </li>
                    <li class="form-row text-input-row">
                        <label><strong>Pregunta 2:</strong></label>
                        <input type="text" name="preg_veh2" class="text-input required" required/>
                    </li>
                    <li class="form-row text-input-row">
                        <label><strong>Pregunta 3:</strong></label>
                        <input type="text" name="preg_veh3" class="text-input required" required/>
                    </li>
                    <li class="form-row text-input-row">
                        <label><strong>Pregunta 4:</strong></label>
                        <input type="text" name="preg_veh4" class="text-input required" required/>
                    </li>
                    <br/>',
                    '</ol>',
            '</fieldset>';
//        </form>';
//            
        }
        
        pg_close($conex);
    }
    
    function extraer($idencuesta){
        include(dirname(dirname(__FILE__)).'/accesobd.php');
        
        $sente2 = pg_query($conex,"SELECT enc.preg FROM encpreg as enc WHERE enc.idenc = $idencuesta[0]");

        $arreglo = pg_fetch_array($sente2);
        
        return ($arreglo);
        
    }
?>

